Enhanced formatting capabilities#955
Merged
michelebastione merged 5 commits intoMay 10, 2026
Merged
Conversation
Added deconstruct method polyfill for type `KeyValuePair<TKey, TValue>`
Made the MiniExcelFormatAttribute correctly add cellXfs entries in the styles.xml file by separating the creation and initialization of SheetStyleBuildContext, keeping track of the column mappings and their relative styles through the new SheetStyleFormatsCache class. The redundant utilities SheetStyleBuilderHelper and SheetStyleBuildResult have been removed, and tests have been updated to reflect the changes.
Changed OpenXmlWriter to treat TimeSpan values as the number of seconds from the start of the day, when less than a single day, or as the number of seconds after 1899/12/31 otherwise. Style builders have been edited to include a new cellXfs element as the default style for unformatted time values that still need to be treated as numeric in Excel.
Adjusted `OpenXmlNumberFormatHelper` to accept multiple character currencies as valid formatting literals
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors the OpenXml writing logic to improve style and number format management through the introduction of SheetStyleBuildContext and SheetStyleFormatsCache. It also extends support for additional date and time types, such as DateTimeOffset and TimeSpan, and enhances asynchronous resource disposal. A critical bug was identified in the SheetStyleFormatsCache where the style index counter is incremented for every column mapping regardless of whether the format is unique, which would lead to incorrect style assignments and broken references in the generated Excel files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added proper numerical formatting for numbers, dates and times
Prior to this update
MiniExcelFormatAttributeconverted all values to their string representation according to the specified format, instead of exporting them as numerical values linked to a style element as per the OpenXml specification intended. This prevented the results to be used as actual numerical values e.g. in formulas while still retaining their representation.This PR addresses this problem and fixes it by optimizing the way
SheetStyleBuildContextkeeps track of format mappings to correctly makeDefaultSheetStyleBuilderdynamically add new styles for each distinct one.A new hardcoded style has also been added for automatically displaying
TimeSpanandTimeOnlyas formatted times even when a specific format is not specified by the user.The
OpenXmlNumberFormatHelperutility has also been revised so that it accepts multiple character currencies as valid numeric literals.Closes #506
Fixes #520
Resolves #627